import { createRouter, createWebHashHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';
import ImportMetaUtil from '@/visual/commons/utils/import-meta-util';

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'root',
    redirect: '/visual/dashboardList',
    meta: {
      title: 'root',
    },
  },
  {
    path: '/visual',
    name: 'VisualLayout',
    redirect: '/visual/dashboardList',
    component: () => import('@/visual/layouts/VisualLayout.vue'),
    meta: {
      title: '可视化',
      noCache: true,
    },
    children: ImportMetaUtil.getRouterModules([
      import.meta.glob('@/visual/routers/visual-layout/**/*.ts', { eager: true }),
    ]),
  },
  {
    path: '/dashboard',
    name: 'DashboardLayout',
    redirect: '/dashboard/DashboardAdd',
    component: () => import('@/visual/layouts/DashboardLayout.vue'),
    meta: {
      title: '仪表板',
      noCache: true,
    },
    children: ImportMetaUtil.getRouterModules([
      import.meta.glob('@/visual/routers/dashboard-layout/**/*.ts', { eager: true }),
    ]),
  },
];

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes,
});

export default router;
